package demo2;

class Solution1 {
    public int[] searchRange(int[] nums, int target) {
        if(nums == null || nums.length ==0) return new int[]{-1,-1} ;
        int start = -1  , end = -1 ; 
         int left = 0 , right =nums.length-1 ;
         while(left < right){
            int mid = left + (right-left)/2 ;
            if(nums[mid] >= target){
                right = mid ;
            }else{
                left = mid + 1 ;
            }
         }
         if(nums[left] != target) return new int[]{-1,-1};
         start = left ; 
         left = 0 ;
         right = nums.length -1 ;
           while(left < right){
            int mid = left + (right-left+1)/2 ;
            if(nums[mid] <= target){
                left = mid ;
            }else{
                right = mid-1 ;
            }
         }
          end = left ;
        return new int[]{start,end};
    }
}